<?php
/**********************************************************************************
WIKINDX: Bibliographic Management system. v2.x
Copyright (C)

This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program;
if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

The WIKINDX Team 2007
sirfragalot@users.sourceforge.net
**********************************************************************************/
/*****
*	Gateway to the system.  Here, the form variable 'action' is parsed to
*	determine the course of action.
*	All actions and requests pass via this gateway.
*
*	$Header: /cvsroot/wikindx/wikindx3/index.php,v 1.100 2007/12/16 14:06:15 sirfragalot Exp $
*****/


// Attempt to set the memory
include("config.php");
if(isset($WIKINDX_MEMORY_LIMIT) && $WIKINDX_MEMORY_LIMIT && preg_match("/\dM/", $WIKINDX_MEMORY_LIMIT, $null))
	ini_set("memory_limit", $WIKINDX_MEMORY_LIMIT);
			
/* Some memory checking 
*/
/*
  $resultRow = 8;
  $resultRowItemStartPosition = 34;
  $resultRowItemLength = 8;
  $output = array();
  exec('pslist -m ' . getmypid() , $output);
  $memStart = trim(substr($output[$resultRow], $resultRowItemStartPosition, $resultRowItemLength)) / 1000;
*/

// Start the timer
include_once("core/init/SCRIPTTIME.php");
$timer = new SCRIPTTIME();
$WIKINDX_START_TIME = $timer->start;
unset($timer); // clear memory
include_once("core/init/SYSTEMCHECK.php");
include_once("core/init/INIT.php");
include_once("core/authorize/AUTHORIZE.php");
include_once("core/session/SESSION.php");

/**
* This is the id of a user from WKX_user and is used to impose restrictions in core/user/USER.php and core/authorize/AUTHORIZE.php for a user who is 
* not allowed to change user details and who will be prompted for a set username and password when logging on.  Setting it to '0' has no effect. It is mainly used 
* for the WIKINDX test server at http://www.sirfragalot.com/wikindx3/ for the test user 'wikindx::wikindx'.
*/
	$WIKINDX_RESTRICT_USER = 0;

/*****
*	Since 99% of actions require the database to be opened, we open it here.
*	Need to chose which class to use based on the type of RDMS required.
*****/
	include_once("core/sql/SQL.php");
	$db = new SQL();
/*****
*	Initialize the system
*	As INIT starts the session, we must check for 'remember me' cookie requests from MYWIKINDX.php prior to 
*	setting the session.
*****/
	$init = new INIT();
// Get user input in whatever form
	$vars = $init->getVars();
	if(!empty($vars) && array_key_exists('cookie', $vars) && $vars['cookie'] && 
		array_key_exists('uname', $vars) && trim($vars['uname']))
	{
// set the cookie if requested
		include_once("core/cookie/COOKIE.php");
		$cookie = new COOKIE();
		$cookie->storeCookie($vars['uname']);
		unset($cookie);
	}
// start the session
	$init->startSession();
	$session = new SESSION();
  
// Initialize the db queries counter
	$WIKINDX_DB_QUERIES = $init->initDbQueries();
	unset($init);


/*****
*	Create the $authorize object which handles logins and pass the $db object to it.
*****/
	$authorize = new AUTHORIZE($db);
// Are we upgrading the database?
	if($vars && array_key_exists('action', $vars) && ($vars['action'] == 'upgradeDBLogon'))
	{
		if($authorize->gateKeep($vars) === FALSE)
			{}
	}
// Do system check
	$sysCheck = new SYSTEMCHECK($db, $vars);
// If we've updated the database, need to re-create the SQL object since updating uses a different object.
	if($sysCheck->updatedDb)
	{
		$db = new SQL();
		$authorize = new AUTHORIZE($db);
	}
	unset($sysCheck);
// Only superadmin can upgrade the database so set up their environment
	if($vars && array_key_exists('action', $vars) && ($vars['action'] == 'upgradeDB'))
	{
		if($authorize->gateKeep($vars) === FALSE)
			$vars['action'] = 'front';
	}
// User bookmarks can only be added when looking at a single resource's details or resource lists.  Set default behaviour here to remove 'add bookmark' link from menu
	$session->setVar("bookmark_displayAdd", FALSE);
	$session->delVar('bookmark_multiView');
  
/*****
*	First pass through authentication.
*****/
// return from gatekeep is either TRUE (meaning proceed without change) or FALSE (meaning set $vars['action'] = "front') 
// which will print the front page of WIKINDX.
// gatekeep() can itself exit the script (usually to the initial logon prompt)
	if($authorize->gateKeep($vars) === FALSE)
		$vars['action'] = 'front';
	unset($authorize);

/* 
 Check for plug-in modules
 */
include_once("core/modules/LOADMODULES.php");
$loadmodules = new LOADMODULES();
$moduleFound = FALSE;
$moduleList = $loadmodules->readModulesDirectory();
unset($loadmodules); // clear memory
$plugintop = $pluginbottom = '';
$plugintopArray = $pluginbottomArray = array();
// Scan in-line plugin modules
if($moduleList)
{
	foreach($moduleList as $moduleName)
	{
		include_once("modules/" . $moduleName . '/index.php');
// class name must be in the form $dirName . MODULE
		$module = $moduleName . "_MODULE";
		$class = new $module($db, $vars);
		$split = array();
		if(isset($class->pluginaction))
		{
			if($vars && array_key_exists("inlinePluginAction", $vars))
				$split = split("_", $vars["inlinePluginAction"], 2);
			if((sizeof($split) == 2) && ($moduleName == $split[0]))
			{
				$method = $split[1];
				if(method_exists($class, $method))
				{
					$class->{$method}(); // run the method
					if(isset($class->plugintop))
						$plugintopArray[] = $class->plugintop;
					if(isset($class->pluginbottom))
						$pluginbottomArray[] = $class->pluginbottom;
				}
			}
// Default (initial plug-in state)
			else if((isset($vars["action"]) && ($class->pluginaction == $vars["action"])) ||
				(!isset($vars["action"]) && ($class->pluginaction == 'front')))
			{
				if(isset($class->plugintop))
					$plugintopArray[] = $class->plugintop;
				if(isset($class->pluginbottom))
					$pluginbottomArray[] = $class->pluginbottom;
			}
		}
		unset($class);
	}
}

/*****
*	Parse 'action' variable.  If not set we print the front page
*****/
// Front page
	if(!isset($vars["action"]) || ($vars['action'] == 'front') || ($vars['action'] == 'upgradeDB'))
	{
		include_once("core/front/FRONT.php");
		$obj = new FRONT($db);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'correctBackslashContinue')
	{
		include_once("core/init/CORRECTBACKSLASH.php");
		$obj = new CORRECTBACKSLASH($vars);
		$pString = $obj->removeAllSlashes();
	}
	else if($vars["action"] == 'frontNoMenu')
	{
		include_once("core/front/FRONT.php");
		$obj = new FRONT($db);
		$pString = $obj->display(TRUE);
	}
// Superadmin configure options
	else if($vars["action"] == 'adminConfigureDisplay')
	{
		include_once("core/admin/CONFIG.php");
		$obj = new CONFIG($db);
		$pString = $obj->displaySetup(FALSE, TRUE);
	}
	else if($vars["action"] == 'adminConfigure')
	{
		include_once("core/admin/CONFIG.php");
		$obj = new CONFIG($db);
		$pString = $obj->write($vars, TRUE);
		$session->clearArray("config");
	}
	else if($vars["action"] == 'deleteResourceDisplay')
	{
		$session->setVar("deleteResourceLock", FALSE);
		include_once("core/admin/DELETERESOURCE.php");
		$obj = new DELETERESOURCE($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'deleteResourceConfirm')
	{
		include_once("core/admin/DELETERESOURCE.php");
		$obj = new DELETERESOURCE($db, $vars);
		$pString = $obj->gateKeep('confirm');
	}
	else if($vars["action"] == 'deleteResource')
	{
		include_once("core/admin/DELETERESOURCE.php");
		$obj = new DELETERESOURCE($db, $vars);
		$pString = $obj->gateKeep('delete');
	}
	else if($vars["action"] == 'customDisplay')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'customAddInit')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('addInit');
	}
	else if($vars["action"] == 'customAdd')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('add');
	}
	else if($vars["action"] == 'customDeleteInit')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('deleteInit');
	}
	else if($vars["action"] == 'customDeleteConfirm')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('deleteConfirm');
	}
	else if($vars["action"] == 'customDelete')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('delete');
	}
	else if($vars["action"] == 'customEditInit')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('editInit');
	}
	else if($vars["action"] == 'customEditDisplay')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('editDisplay');
	}
	else if($vars["action"] == 'customEdit')
	{
		include_once("core/admin/ADMINCUSTOM.php");
		$obj = new ADMINCUSTOM($db, $vars);
		$pString = $obj->gateKeep('edit');
	}
	else if($vars["action"] == 'adminKeyword')
	{
		include_once("core/admin/ADMINKEYWORD.php");
		$obj = new ADMINKEYWORD($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'mergeKeywords')
	{
		include_once("core/admin/ADMINKEYWORD.php");
		$obj = new ADMINKEYWORD($db, $vars);
		$pString = $obj->gateKeep('mergeProcess');
	}
	else if($vars["action"] == 'adminGroup')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'adminGroupAddInit')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('addInit');
	}
	else if($vars["action"] == 'adminGroupAdd')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('add');
	}
	else if($vars["action"] == 'adminGroupDeleteInit')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('deleteInit');
	}
	else if($vars["action"] == 'adminGroupDeleteConfirm')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('deleteConfirm');
	}
	else if($vars["action"] == 'adminGroupDelete')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('delete');
	}
	else if($vars["action"] == 'adminGroupEditInit')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('editInit');
	}
	else if($vars["action"] == 'adminGroupEdit')
	{
		include_once("core/admin/ADMINGROUP.php");
		$obj = new ADMINGROUP($db, $vars);
		$pString = $obj->gateKeep('edit');
	}
	//Gestion institution
	else if($vars["action"] == 'adminGroup2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'adminGroupAddInit2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('addInit');
	}
	else if($vars["action"] == 'adminGroupAdd2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('add');
	}
	else if($vars["action"] == 'adminGroupDeleteInit2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('deleteInit');
	}
	else if($vars["action"] == 'adminGroupDeleteConfirm2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('deleteConfirm');
	}
	else if($vars["action"] == 'adminGroupDelete2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('delete');
	}
	else if($vars["action"] == 'adminGroupEditDisplay2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('displayEdit');
	}
	else if($vars["action"] == 'adminGroupEditInit2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('editInit');
	}
	else if($vars["action"] == 'adminGroupEdit2')
	{
		include_once("core/admin/ADMINGROUP2.php");
		$obj = new ADMINGROUP2($db, $vars);
		$pString = $obj->gateKeep('edit');
	}
	//
	else if($vars["action"] == 'resourcePasteBibtex')
	{
		include_once("core/file/import/BIBTEXIMPORT.php");
		$obj = new BIBTEXIMPORT($db, $vars);
		$pString = $obj->gatekeep('resourcePasteBibtex');
	}
	else if($vars["action"] == 'resourcePasteBibtexStage2')
	{
		include_once("core/file/import/BIBTEXIMPORT.php");
		$obj = new BIBTEXIMPORT($db, $vars);
		$pString = $obj->gatekeep('resourcePasteBibtexStage2');
	}
	else if($vars["action"] == 'resourcePasteBibtexStage3')
	{
		include_once("core/file/import/BIBTEXIMPORT.php");
		$obj = new BIBTEXIMPORT($db, $vars);
		$pString = $obj->gatekeep('resourcePasteBibtexStage3');
	}
	else if($vars["action"] == 'importBibtexStage1')
	{
		include_once("core/file/import/BIBTEXIMPORT.php");
		$obj = new BIBTEXIMPORT($db, $vars);
		$pString = $obj->gatekeep('importBibtexStage1');
	}
	else if($vars["action"] == 'importBibtexStage2')
	{
		include_once("core/file/import/BIBTEXIMPORT.php");
		$obj = new BIBTEXIMPORT($db, $vars);
		$pString = $obj->gatekeep('importBibtexStage2');
	}
	else if($vars["action"] == 'importBibtexStage3')
	{
		include_once("core/file/import/BIBTEXIMPORT.php");
		$obj = new BIBTEXIMPORT($db, $vars);
		$pString = $obj->gatekeep('importBibtexStage3');
	}
	else if($vars["action"] == 'importBibtexStage3Continue')
	{
		include_once("core/file/import/BIBTEXIMPORT.php");
		$obj = new BIBTEXIMPORT($db, $vars);
		$pString = $obj->gatekeep('importBibtexStage3Continue');
	}
	else if($vars["action"] == 'importEndnoteStage1')
	{
		include_once("core/file/import/ENDNOTEIMPORT.php");
		$obj = new ENDNOTEIMPORT($db, $vars);
		$pString = $obj->gatekeep('importEndnoteStage1');
	}
	else if($vars["action"] == 'importEndnoteStage2')
	{
		include_once("core/file/import/ENDNOTEIMPORT.php");
		$obj = new ENDNOTEIMPORT($db, $vars);
		$pString = $obj->gatekeep('importEndnoteStage2');
	}
	else if($vars["action"] == 'importEndnoteStage2Continue')
	{
		include_once("core/file/import/ENDNOTEIMPORT.php");
		$obj = new ENDNOTEIMPORT($db, $vars);
		$pString = $obj->gatekeep('importEndnoteStage2Continue');
	}
	else if($vars["action"] == 'importEndnoteStage3')
	{
		include_once("core/file/import/ENDNOTEIMPORT.php");
		$obj = new ENDNOTEIMPORT($db, $vars);
		$pString = $obj->gatekeep('importEndnoteStage3');
	}
	else if($vars["action"] == 'adminNoMenu')
	{
		include_once("core/admin/ADMIN.php");
		$obj = new ADMIN($db);
		$pString = $obj->display(TRUE);
	}
	else if($vars["action"] == 'resourceNew')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('newResource');
	}
	else if($vars["action"] == 'resourceEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editResource');
	}
	else if($vars["action"] == 'resourceKeywordCategoryEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editResourceKeywordCategory');
	}
	else if($vars["action"] == 'resourceKeywordCategoryWrite')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('writeResourceKeywordCategory');
	}
	else if($vars["action"] == 'resourceWrite')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('writeResource');
	}
	else if($vars["action"] == 'resourceView')
	{
		include_once("core/resource/RESOURCEVIEW.php");
		$obj = new RESOURCEVIEW($db, $vars);
		$pString = $obj->view();
	}
	else if($vars["action"] == 'randomResource')
	{
		include_once("core/resource/RESOURCEVIEW.php");
		$obj = new RESOURCEVIEW($db, $vars);
		$pString = $obj->random();
	}
	else if($vars["action"] == 'formatResourceView')
	{
		include_once("core/resource/RESOURCEVIEW.php");
		$obj = new RESOURCEVIEW($db, $vars);
//		$pString = $obj->formatResourceView();
	}
	else if($vars["action"] == 'lastSolo')
	{
		include_once("core/resource/RESOURCEVIEW.php");
		$obj = new RESOURCEVIEW($db, $vars);
		$pString = $obj->view(FALSE, 'lastSolo');
	}
	else if($vars["action"] == 'resourceNoMenu')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->display(TRUE);
	}
	else if($vars["action"] == 'selectMetaDisplay')
	{
		include_once("core/list/SELECTMETADATA.php");
		$obj = new SELECTMETADATA($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'selectMetaProcess')
	{
		include_once("core/list/SELECTMETADATA.php");
		$obj = new SELECTMETADATA($db, $vars);
		$pString = $obj->process('html');
	}
	else if($vars["action"] == 'metaKeywordProcess')
	{
		$vars['selectMeta_method'] = 'keyword';
		$vars['selectMeta_keyword'] = array($vars['id']);
		include_once("core/list/SELECTMETADATA.php");
		$obj = new SELECTMETADATA($db, $vars);
		$pString = $obj->process('html');
	}
	else if($vars["action"] == 'searchMetaDisplay')
	{
		include_once("core/list/SEARCHMETADATA.php");
		$obj = new SEARCHMETADATA($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'searchMetaProcess')
	{
		include_once("core/list/SEARCHMETADATA.php");
		$obj = new SEARCHMETADATA($db, $vars);
		$pString = $obj->process('html');
	}
	else if($vars["action"] == 'browseMetaKeyword')
	{
		include_once("core/browse/BROWSEKEYWORD.php");
		$obj = new BROWSEKEYWORD($db, $vars);
		$pString = $obj->displayMeta();
	}
	else if($vars["action"] == 'lastMultiMeta')
	{
		if($session->getVar('sql_lastMultiMeta') == 'select')
		{
			include_once("core/list/SELECTMETADATA.php");
			$obj = new SELECTMETADATA($db, $vars);
			$pString = $obj->process('html');
		}
		if($session->getVar('sql_lastMultiMeta') == 'search')
		{
			include_once("core/list/SEARCHMETADATA.php");
			$obj = new SEARCHMETADATA($db, $vars);
			$pString = $obj->process('html');
		}
	}
	else if($vars["action"] == 'metaExportRtf')
	{
		if($session->getVar('sql_lastMultiMeta') == 'select')
		{
			include_once("core/list/SELECTMETADATA.php");
			$obj = new SELECTMETADATA($db, $vars);
			$pString = $obj->process('rtf');
		}
		if($session->getVar('sql_lastMultiMeta') == 'search')
		{
			include_once("core/list/SEARCHMETADATA.php");
			$obj = new SEARCHMETADATA($db, $vars);
			$pString = $obj->process('rtf');
		}
	}
	else if($vars["action"] == 'suwpMetaProcess')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->suwpMetaProcess();
	}
	else if($vars["action"] == 'allMusings')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->allMusings();
	}
	else if($vars["action"] == 'randomMusing')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->randomMusing();
	}
	else if($vars["action"] == 'allQuotes')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->allQuotes();
	}
	else if($vars["action"] == 'randomQuote')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->randomQuote();
	}
	else if($vars["action"] == 'allParaphrases')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->allParaphrases();
	}
	else if($vars["action"] == 'randomParaphrase')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->randomParaphrase();
	}
	else if($vars["action"] == 'textNoMenu')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->display(TRUE);
	}
	else if($vars["action"] == 'suwpMetadataDisplay')
	{
		include_once("core/text/TEXT.php");
		$obj = new TEXT($db, $vars);
		$pString = $obj->suwpMetadataDisplay();
	}
	else if($vars["action"] == 'suwpAppendPaperDisplay')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("listAppendWp");
	}
	else if($vars["action"] == 'wpLoadAppend')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpLoadAppend");
	}
	else if($vars["action"] == 'noteEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editNote');
	}
	else if($vars["action"] == 'quoteEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editQuote');
	}
	else if($vars["action"] == 'paraphraseEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editParaphrase');
	}
	else if($vars["action"] == 'musingEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editMusing');
	}
	else if($vars["action"] == 'abstractEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editAbstract');
	}
	else if($vars["action"] == 'userCustomEdit')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('editCustom');
	}
	else if($vars["action"] == 'selectedResourceTo')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('selectedResourceTo');
	}
	else if($vars["action"] == 'addResourceToCategory')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('addResourceToCategory');
	}
	else if($vars["action"] == 'addResourceToKeyword')
	{
		include_once("core/resource/RESOURCE.php");
		$obj = new RESOURCE($db, $vars);
		$pString = $obj->gateKeep('addResourceToKeyword');
	}
	else if($vars["action"] == 'listDisplay')
	{
		include_once("core/list/LISTRESOURCES.php");
		$obj = new LISTRESOURCES($db, $vars);
		$pString = $obj->display();
	}
	else if(($vars["action"] == 'listProcess') || ($vars["action"] == 'listProcessAdded') || 
		($vars["action"] == 'listProcessEdited'))
	{
		include_once("core/list/LISTRESOURCES.php");
		$obj = new LISTRESOURCES($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'listReorder')
	{
		include_once("core/list/LISTRESOURCES.php");
		$obj = new LISTRESOURCES($db, $vars);
		$pString = $obj->process(FALSE, TRUE);
	}
	else if($vars["action"] == 'listCategoryProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->categoryProcess();
	}
	else if($vars["action"] == 'listKeywordProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->keywordProcess();
	}
	else if($vars["action"] == 'listInstitutionProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->institutionProcess();
	}
	else if($vars["action"] == 'listCreatorProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->creatorProcess();
	}
	else if($vars["action"] == 'listPublisherProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->publisherProcess();
	}
	else if($vars["action"] == 'listConfPublisherProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->publisherProcess(FALSE, TRUE);
	}
	else if($vars["action"] == 'listCollectionProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->collectionProcess();
	}
	else if($vars["action"] == 'listCiteProcess')
	{
		include_once("core/list/LISTSOMERESOURCES.php");
		$obj = new LISTSOMERESOURCES($db, $vars);
		$pString = $obj->citeProcess();
	}
	else if($vars["action"] == 'selectDisplay')
	{
		include_once("core/list/SELECTRESOURCES.php");
		$obj = new SELECTRESOURCES($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'selectProcess')
	{
		include_once("core/list/SELECTRESOURCES.php");
		$obj = new SELECTRESOURCES($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'selectReorder')
	{
		include_once("core/list/SELECTRESOURCES.php");
		$obj = new SELECTRESOURCES($db, $vars);
		$pString = $obj->process(FALSE, TRUE);
	}
	else if($vars["action"] == 'statisticsReorder')
	{
		$vars['statistics'] = $session->getVar('statistics_type');
		$vars['id'] = $session->getVar('statistics_id');
		include_once("core/list/SELECTRESOURCES.php");
		$obj = new SELECTRESOURCES($db, $vars);
		$pString = $obj->process(FALSE, TRUE);
	}
	else if($vars["action"] == 'searchDisplay')
	{
		include_once("core/list/SEARCHRESOURCES.php");
		$obj = new SEARCHRESOURCES($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'searchProcess')
	{
		include_once("core/list/SEARCHRESOURCES.php");
		$obj = new SEARCHRESOURCES($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'searchReorder')
	{
		include_once("core/list/SEARCHRESOURCES.php");
		$obj = new SEARCHRESOURCES($db, $vars);
		$pString = $obj->process(FALSE, TRUE);
	}
	else if($vars["action"] == 'powerSearchDisplay')
	{
		include_once("core/list/POWERSEARCHRESOURCES.php");
		$obj = new POWERSEARCHRESOURCES($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'powerSearchProcess')
	{
		include_once("core/list/POWERSEARCHRESOURCES.php");
		$obj = new POWERSEARCHRESOURCES($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'browseInstitution')
	{
		include_once("core/browse/BROWSEINSTITUTION.php");
		$obj = new BROWSEINSTITUTION($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'browseCreator')
	{
		include_once("core/browse/BROWSECREATOR.php");
		$obj = new BROWSECREATOR($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'browseCreator2')
	{
		include_once("core/browse/BROWSECREATOR2.php");
		$obj = new BROWSECREATOR2($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'browseKeyword')
	{
		include_once("core/browse/BROWSEKEYWORD.php");
		$obj = new BROWSEKEYWORD($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'browseCollection1')
	{
		include_once("core/browse/BROWSECOLLECTION.php");
		$obj = new BROWSECOLLECTION($db, $vars);
		$pString = $obj->display1();
	}
	else if($vars["action"] == 'browseCollection2')
	{
		include_once("core/browse/BROWSECOLLECTION.php");
		$obj = new BROWSECOLLECTION($db, $vars);
		$pString = $obj->display2();
	}
	else if($vars["action"] == 'browseCategory')
	{
		include_once("core/browse/BROWSECATEGORY.php");
		$obj = new BROWSECATEGORY($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'browsePublisher')
	{
		include_once("core/browse/BROWSEPUBLISHER.php");
		$obj = new BROWSEPUBLISHER($db, $vars);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'lastMulti')
	{
		if($session->getVar('sql_lastMulti') == 'select')
		{
			include_once("core/list/SELECTRESOURCES.php");
			$obj = new SELECTRESOURCES($db, $vars);
			$pString = $obj->process();
		}
		else if($session->getVar('sql_lastMulti') == 'statistics')
		{
			include_once("core/list/SELECTRESOURCES.php");
			$vars['statistics'] = $session->getVar('statistics_type');
			$vars['id'] = $session->getVar('statistics_id');
			$obj = new SELECTRESOURCES($db, $vars);
			$pString = $obj->process();
		}
		else if($session->getVar('sql_lastMulti') == 'list')
		{
			include_once("core/list/LISTRESOURCES.php");
			$obj = new LISTRESOURCES($db, $vars);
			$pString = $obj->process();
		}
		else if($session->getVar('sql_lastMulti') == 'search')
		{
			include_once("core/list/SEARCHRESOURCES.php");
			$obj = new SEARCHRESOURCES($db, $vars);
			$pString = $obj->process();
		}
		else if($session->getVar('sql_lastMulti') == 'powerSearch')
		{
			include_once("core/list/POWERSEARCHRESOURCES.php");
			$obj = new POWERSEARCHRESOURCES($db, $vars);
			$pString = $obj->process();
		}
		else if($session->getVar('sql_lastMulti') == 'listCategory')
		{
			include_once("core/list/LISTSOMERESOURCES.php");
			$obj = new LISTSOMERESOURCES($db, $vars);
			$pString = $obj->categoryProcess();
		}
		// else if($session->getVar('sql_lastMulti') == 'listInstitution')
		// {
			// include_once("core/list/LISTSOMERESOURCES.php");
			// $obj = new LISTSOMERESOURCES($db, $vars);
			// $pString = $obj->categoryProcess();
		// }
		else if($session->getVar('sql_lastMulti') == 'listCreator')
		{
			include_once("core/list/LISTSOMERESOURCES.php");
			$obj = new LISTSOMERESOURCES($db, $vars);
			$pString = $obj->creatorProcess();
		}
		else if($session->getVar('sql_lastMulti') == 'listPublisher')
		{
			include_once("core/list/LISTSOMERESOURCES.php");
			$obj = new LISTSOMERESOURCES($db, $vars);
			$pString = $obj->publisherProcess();
		}
		else if($session->getVar('sql_lastMulti') == 'listCollection')
		{
			include_once("core/list/LISTSOMERESOURCES.php");
			$obj = new LISTSOMERESOURCES($db, $vars);
			$pString = $obj->collectionProcess();
		}
		else if($session->getVar('sql_lastMulti') == 'listKeyword')
		{
			include_once("core/list/LISTSOMERESOURCES.php");
			$obj = new LISTSOMERESOURCES($db, $vars);
			$pString = $obj->keywordProcess();
		}
		else if($session->getVar('sql_lastMulti') == 'listCite')
		{
			include_once("core/list/LISTSOMERESOURCES.php");
			$obj = new LISTSOMERESOURCES($db, $vars);
			$pString = $obj->citeProcess();
		}
		else if($session->getVar('sql_lastMulti') == 'basket')
		{
			include_once("core/basket/BASKET.php");
			$obj = new BASKET($db, $vars);
			$pString = $obj->view();
		}
		else
		{
// That session has disappeared so return resource page with noMenu options as kludgey fix
			include_once("core/resource/RESOURCE.php");
			$obj = new RESOURCE($db, $vars);
			$pString = $obj->display(TRUE);
		}
	}
	else if($vars["action"] == 'aboutWikindx')
	{
		include_once("core/messages/ABOUT.php");
		$pString = ABOUT::display();
	}
	else if($vars["action"] == 'preferencesDisplay')
	{
		$session->clearArray("preferences");
		include_once("core/preferences/PREFERENCES.php");
		$obj = new PREFERENCES($db);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'preferencesWrite')
	{
		include_once("core/preferences/PREFERENCES.php");
		$obj = new PREFERENCES($db);
		$pString = $obj->write($vars);
	}
	else if($vars["action"] == 'helpNoMenu')
	{
		include_once("core/messages/HELP.php");
		$obj = new HELP();
		$pString = $obj->display(TRUE);
	}
	else if($vars["action"] == 'helpDisplay')
	{
		include_once("core/messages/HELP.php");
		$obj = new HELP();
		$pString = $obj->display();
	}
	else if($vars["action"] == 'usingWikindx')
	{
		include_once("core/messages/USINGWIKINDX.php");
		$obj = new USINGWIKINDX();
		$pString = $obj->display();
	}
	else if($vars["action"] == 'helpImportDisplay')
	{
		include_once("core/messages/HELPIMPORT.php");
		$pString = HELPIMPORT::display();
	}
	else if($vars["action"] == 'helpConfigDisplay')
	{
		include_once("core/messages/HELPCONFIG.php");
		$pString = HELPCONFIG::display();
	}
	else if($vars["action"] == 'helpStyleDisplay')
	{
		include_once("core/messages/HELPSTYLE.php");
		$pString = HELPSTYLE::display();
	}
	else if($vars["action"] == 'fileNoMenu')
	{
		include_once("core/file/FILE.php");
		$obj = new FILE($db);
		$pString = $obj->display(TRUE);
	}
	else if($vars["action"] == 'exportRtfSetup')
	{
		include_once("core/file/export/RTF.php");
		$obj = new RTF($db);
		$pString = $obj->setup();
	}
	else if($vars["action"] == 'exportRtf')
	{
		include_once("core/file/export/RTF.php");
		$obj = new RTF($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'bibtexDisplay')
	{
		include_once("core/file/export/BIBTEX.php");
		$obj = new BIBTEX($db, $vars);
		$obj->closeNoMenu = TRUE;
		$obj->bibtexDisplay(); // calls CLOSE() internally
	}
	else if($vars["action"] == 'exportBibtexStage1')
	{
		include_once("core/file/export/BIBTEX.php");
		$obj = new BIBTEX($db, FALSE);
		$pString = $obj->stage1();
	}
	else if($vars["action"] == 'exportBibtex')
	{
		include_once("core/file/export/BIBTEX.php");
		$obj = new BIBTEX($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'exportRis')
	{
		include_once("core/file/export/RIS.php");
		$obj = new RIS($db);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'exportEndnoteStage1')
	{
		include_once("core/file/export/ENDNOTE.php");
		$obj = new ENDNOTE($db, FALSE);
		$pString = $obj->stage1();
	}
	else if($vars["action"] == 'exportEndnote')
	{
		include_once("core/file/export/ENDNOTE.php");
		$obj = new ENDNOTE($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'exportEndnoteXmlStage1')
	{
		include_once("core/file/export/ENDNOTEXML.php");
		$obj = new ENDNOTEXML($db, FALSE);
		$pString = $obj->stage1();
	}
	else if($vars["action"] == 'exportEndnoteXml')
	{
		include_once("core/file/export/ENDNOTEXML.php");
		$obj = new ENDNOTEXML($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'exportHtml')
	{
		include_once("core/file/export/HTMLEXPORT.php");
		$obj = new HTMLEXPORT($db);
		$pString = $obj->display();
	}
	else if($vars["action"] == 'exportHtmlProcess')
	{
		include_once("core/file/export/HTMLEXPORT.php");
		$obj = new HTMLEXPORT($db, $vars);
		$pString = $obj->process();
	}
	else if($vars["action"] == 'showFiles')
	{
		include_once("core/file/FILE.php");
		$obj = new FILE($db);
		$pString = $obj->show();
	}
	else if($vars["action"] == 'editNoMenu')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->display(TRUE);
	}
	//
	else if($vars["action"] == 'editCreator')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editCreator');
	}
	else if($vars["action"] == 'editCreatorConfirm')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editCreatorConfirm');
	}
	//
	else if($vars["action"] == 'editCollection')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editCollection');
	}
	else if($vars["action"] == 'editCollectionChooseType')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editCollectionChooseType');
	}
	else if($vars["action"] == 'editCollectionSetCreators')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editCollectionSetCreators');
	}
	else if($vars["action"] == 'editCollectionConfirm')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editCollectionConfirm');
	}
	else if($vars["action"] == 'editPublisher')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editPublisher');
	}
	else if($vars["action"] == 'editPublisherConfirm')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editPublisherConfirm');
	}
	else if($vars["action"] == 'editKeyword')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editKeyword');
	}
	else if($vars["action"] == 'editKeywordConfirm')
	{
		include_once("core/edit/EDIT.php");
		$obj = new EDIT($db, $vars);
		$pString = $obj->gatekeep('editKeywordConfirm');
	}
	else if($vars["action"] == 'initLogon')
	{
		$obj = new AUTHORIZE($db);
		$pString = $obj->initLogon();
		unset($obj);
		if(!$session->getVar("setup_readOnly"))
		{
			include_once("core/html/CLOSENOMENU.php");
			new CLOSENOMENU($db, $pString);
		}
		else
		{
			include_once("core/html/CLOSE.php");
			new CLOSE($db, $pString);
		}
	}
	else if($vars["action"] == 'adminUser')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'adminUserAddInit')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('addInit');
	}
	else if($vars["action"] == 'adminUserAdd')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('add');
	}
	else if($vars["action"] == 'adminUserDeleteInit')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('deleteInit');
	}
	else if($vars["action"] == 'adminUserDeleteConfirm')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('deleteConfirm');
	}
	else if($vars["action"] == 'adminUserDelete')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('delete');
	}
	else if($vars["action"] == 'adminUserEditInit')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('editInit');
	}
	else if($vars["action"] == 'adminUserEditDisplay')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('editDisplay');
	}
	else if($vars["action"] == 'adminUserEdit')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString = $obj->gateKeep('edit');
	}
	else if($vars["action"] == 'forgetSet')
	{
		include_once("core/user/USER.php");
		$obj = new USER($db, $vars);
		$pString = $obj->gateKeep('forgetSet');
	}
	else if($vars["action"] == 'forgetInitStage1')
	{
		$obj = new AUTHORIZE($db);
		$pString = $obj->forgetInitStage1();
		include_once("core/html/CLOSENOMENU.php");
		new CLOSENOMENU($db, $pString);
	}
	else if($vars["action"] == 'forgetInitStage2')
	{
		$obj = new AUTHORIZE($db);
		$pString = $obj->forgetInitStage2($vars);
		include_once("core/html/CLOSENOMENU.php");
		new CLOSENOMENU($db, $pString);
	}
	else if($vars["action"] == 'forgetProcess')
	{
		$obj = new AUTHORIZE($db);
		$pString = $obj->forgetProcess($vars);
		include_once("core/html/CLOSENOMENU.php");
		new CLOSENOMENU($db, $pString);
	}
	else if($vars["action"] == 'initMyWikindx')
	{
		include_once("core/user/USER.php");
		$obj = new USER($db, $vars);
		$pString = $obj->gateKeep('initDisplay');
	}
	else if($vars["action"] == 'myWikindxUserEdit')
	{
		include_once("core/user/USER.php");
		$obj = new USER($db, $vars);
		$pString = $obj->gateKeep('userEdit');
	}
	else if($vars["action"] == 'initBibliographies')
	{
		include_once("core/user/BIBLIOGRAPHY.php");
		$obj = new BIBLIOGRAPHY($db, $vars);
		$pString = $obj->initDisplay();
	}
	else if($vars["action"] == 'bibliographies')
	{
		include_once("core/user/BIBLIOGRAPHY.php");
		$obj = new BIBLIOGRAPHY($db, $vars);
		$pString = $obj->sortMethod();
	}
	else if($vars["action"] == 'myWikindxBibliography')
	{
		include_once("core/user/MYWIKINDX.php");
		$obj = new MYWIKINDX($db, $vars);
		$pString = $obj->gateKeep();
	}
	else if($vars["action"] == 'myWikindxGroupBibliography')
	{
		include_once("core/user/MYWIKINDX.php");
		$obj = new MYWIKINDX($db, $vars);
		$pString = $obj->gateKeep();
	}
	else if($vars["action"] == 'myWikindxUserGroup')
	{
		include_once("core/user/MYWIKINDX.php");
		$obj = new MYWIKINDX($db, $vars);
		$pString = $obj->gateKeep();
	}
	else if($vars["action"] == "myWikindxNotifyEdit")
	{
		include_once("core/user/MYWIKINDX.php");
		$obj = new MYWIKINDX($db, $vars);
		$pString = $obj->gateKeep();
	}
	else if($vars["action"] == "adminNews")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("initAdmin");
	}
	else if($vars["action"] == "newsAddInit")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("initNewsAdd");
	}
	else if($vars["action"] == "newsAdd")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("add");
	}
	else if($vars["action"] == "newsDeleteInit")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("deleteInit");
	}
	else if($vars["action"] == "newsDeleteConfirm")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("deleteConfirm");
	}
	else if($vars["action"] == "newsDelete")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("delete");
	}
	else if($vars["action"] == "newsEditInit")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("editInit");
	}
	else if($vars["action"] == "newsEditDisplay")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("editDisplay");
	}
	else if($vars["action"] == "newsEdit")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->gateKeep("edit");
	}
	else if($vars["action"] == "viewNews")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->viewNews();
	}
	else if($vars["action"] == "viewNewsItem")
	{
		include_once("core/news/NEWS.php");
		$obj = new NEWS($db, $vars);
		$pString = $obj->viewNewsItem();
	}
// Display pop up citation window with search form
	else if($vars["action"] == "citeDisplay")
	{
		include_once("core/cite/CITE.php");
		$obj = new CITE($db, $vars);
		$pString = $obj->display();
	}
// Display pop up citation window with search results
	else if($vars["action"] == "citeSearchProcess")
	{
		include_once("core/cite/CITE.php");
		$obj = new CITE($db, $vars);
		$pString = $obj->citeSearchProcess();
	}
// Administer bibliographic styles
	else if($vars["action"] == 'adminStyle')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'adminStyleAddInit')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('addInit');
	}
	else if($vars["action"] == 'adminStyleAdd')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('add');
	}
	else if($vars["action"] == 'adminStyleEditInit')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('editInit');
	}
	else if($vars["action"] == 'adminStyleEditDisplay')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('editDisplay');
	}
	else if($vars["action"] == 'adminStyleEdit')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('edit');
	}
	else if($vars["action"] == 'adminStyleCopyInit')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('copyInit');
	}
	else if($vars["action"] == 'adminStyleCopyDisplay')
	{
		include_once("core/admin/ADMINSTYLE.php");
		$obj = new ADMINSTYLE($db, $vars);
		$pString = $obj->gateKeep('copyDisplay');
	}
// File attachments
	else if($vars["action"] == 'fileAddDisplay')
	{
		include_once("core/attachments/ATTACHMENTS.php");
		$obj = new ATTACHMENTS($db, $vars);
		$pString = $obj->gatekeep('addDisplay');
	}
	else if($vars["action"] == 'fileAdd')
	{
		include_once("core/attachments/ATTACHMENTS.php");
		$obj = new ATTACHMENTS($db, $vars);
		$pString = $obj->gatekeep('fileAdd');
	}
	else if($vars["action"] == 'fileDeleteDisplay')
	{
		include_once("core/attachments/ATTACHMENTS.php");
		$obj = new ATTACHMENTS($db, $vars);
		$pString = $obj->gatekeep('deleteDisplay');
	}
	else if($vars["action"] == 'fileDeleteConfirm')
	{
		include_once("core/attachments/ATTACHMENTS.php");
		$obj = new ATTACHMENTS($db, $vars);
		$pString = $obj->gatekeep('deleteConfirm');
	}
	else if($vars["action"] == 'fileDelete')
	{
		include_once("core/attachments/ATTACHMENTS.php");
		$obj = new ATTACHMENTS($db, $vars);
		$pString = $obj->gatekeep('delete');
	}
	else if($vars["action"] == 'fileDownload')
	{
		include_once("core/attachments/ATTACHMENTS.php");
		$obj = new ATTACHMENTS($db, $vars);
		$obj->download(); // Method dies
	}
// Single-user Word Processor functions
	else if($vars["action"] == 'wpBrowserTry')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpBrowserTry");
	}
	else if($vars["action"] == 'wpNoMenu')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpDisplay");
	}
	else if($vars["action"] == 'wpNew')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpNew");
	}
	else if($vars["action"] == 'wpList')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpList");
	}
	else if($vars["action"] == 'wpFileDownload')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpFileDownload");
	}
	else if($vars["action"] == 'wpExportDownload')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpExportDownload");
	}
	else if($vars["action"] == 'wpListOpen')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpListOpen");
	}
	else if($vars["action"] == 'wpListDelete')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpListDelete");
	}
	else if($vars["action"] == 'wpOpen')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpOpen");
	}
	else if($vars["action"] == 'wpDeleteConfirm')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpDeleteConfirm");
	}
	else if($vars["action"] == 'wpDelete')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpDelete");
	}
	else if($vars["action"] == 'wpSaveDialogue')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpSaveDialogue");
		unset($obj);
		include_once("core/html/CLOSEPOPUP.php");
		new CLOSEPOPUP($pString);
	}
	else if($vars["action"] == 'wpSaveExportDialogue')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpSaveExportDialogue");
		unset($obj);
		include_once("core/html/CLOSEPOPUP.php");
		new CLOSEPOPUP($pString);
	}
	else if($vars["action"] == 'wpSave')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpSave");
	}
	else if($vars["action"] == 'wpRevertConfirm')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpRevertConfirm");
	}
	else if($vars["action"] == 'wpRevert')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpRevert");
	}
	else if($vars["action"] == 'wpImportInit')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpImportInit");
	}
	else if($vars["action"] == 'wpImport')
	{
		include_once("core/wp/WP.php");
		$obj = new WP($db, $vars);
		$pString = $obj->gateKeep("wpImport");
	}
	else if($vars["action"] == 'exportDownload')
	{
		include_once("core/file/FILE.php");
		$obj = new FILE($db);
		$obj->exportDownload($vars);
	}
// User bookmark functions
	else if($vars["action"] == 'bookmarkNoMenu')
	{
		include_once("core/user/BOOKMARK.php");
		$obj = new BOOKMARK($db, $vars);
		$pString = $obj->display(TRUE);
	}
	else if($vars["action"] == 'bookmarkAddInit')
	{
		include_once("core/user/BOOKMARK.php");
		$obj = new BOOKMARK($db, $vars);
		$pString = $obj->addInit();
	}
	else if($vars["action"] == 'bookmarkAdd')
	{
		include_once("core/user/BOOKMARK.php");
		$obj = new BOOKMARK($db, $vars);
		$pString = $obj->add();
	}
	else if($vars["action"] == 'bookmarkDeleteInit')
	{
		include_once("core/user/BOOKMARK.php");
		$obj = new BOOKMARK($db, $vars);
		$pString = $obj->deleteInit();
	}
	else if($vars["action"] == 'bookmarkDelete')
	{
		include_once("core/user/BOOKMARK.php");
		$obj = new BOOKMARK($db, $vars);
		$pString = $obj->delete();
	}
	else if($vars["action"] == 'bookmarkMultiView')
	{
		include_once("core/user/BOOKMARK.php");
		$obj = new BOOKMARK($db, $vars);
		$pString = $obj->multiView();
	}
// In-text citation creation/editing preview
	else if($vars["action"] == 'previewCite')
	{
		include_once("core/styles/PREVIEWCITE.php");
		$obj = new PREVIEWCITE($vars);
		$pString = $obj->display();
		unset($obj);
		include_once("core/html/CLOSEPOPUP.php");
		new CLOSEPOPUP($pString);
	}
// Bibliographic style creation/editing preview
	else if($vars["action"] == 'previewStyle')
	{
		include_once("core/styles/PREVIEWSTYLE.php");
		$obj = new PREVIEWSTYLE($vars);
		$pString = $obj->display();
		unset($obj);
		include_once("core/html/CLOSEPOPUP.php");
		new CLOSEPOPUP($pString);
	}
// Bibliographic style creation/editing preview
	else if($vars["action"] == 'previewStyleFields')
	{
		//$pString = print_r($vars);
		include_once("core/styles/PREVIEWSTYLE.php");
		$obj = new PREVIEWSTYLE($vars);
		$pString = $obj->display(TRUE);
		unset($obj);
		include_once("core/html/CLOSEPOPUP.php");
		new CLOSEPOPUP($pString);
	}
// Resource basket operations
	else if($vars["action"] == 'basketAdd')
	{
		include_once("core/basket/BASKET.php");
		$obj = new BASKET($db, $vars);
		$obj->add(); // CLOSE() called in function
	}
	else if($vars["action"] == 'basketRemove')
	{
		include_once("core/basket/BASKET.php");
		$obj = new BASKET($db, $vars);
		$obj->remove(); // CLOSE() called in function
	}
	else if($vars["action"] == 'basketView')
	{
		include_once("core/basket/BASKET.php");
		$obj = new BASKET($db, $vars);
		$pString = $obj->view();
	}
	else if($vars["action"] == 'basketDelete')
	{
		include_once("core/basket/BASKET.php");
		$obj = new BASKET($db, $vars);
		$pString = $obj->delete();
	}
	else if($vars["action"] == 'basketDeleteConfirm')
	{
		include_once("core/basket/BASKET.php");
		$obj = new BASKET($db, $vars);
		$pString = $obj->delete(TRUE);
	}
// Display of statistics
	else if($vars["action"] == 'statisticsDisplay')
	{
		include_once("core/statistics/STATISTICS.php");
		$obj = new STATISTICS($db, $vars);
		$pString = $obj->gateKeep('display');
	}
// Browsing category tree
	else if($vars["action"] == 'categoryTree')
	{
		include_once("core/browse/CATEGORYTREE.php");
		$obj = new CATEGORYTREE($db);
		$pString = $obj->display();
	}
// Set the maturity index
	else if($vars["action"] == 'setMaturityIndex')
	{
		include_once("core/statistics/STATISTICS.php");
		$obj = new STATISTICS($db, $vars);
		$pString = $obj->setMaturityIndex();
	}
// Save wikindx session state
	else if($vars["action"] == 'saveWikindxState')
	{
		$obj = new AUTHORIZE($db);
		$pString = $obj->writeEnvironment(TRUE);
	}
// Email single resource to friend
	else if($vars["action"] == 'emailFriendDisplay')
	{
		include_once("core/email/EMAIL.php");
		$obj = new EMAIL(FALSE, $vars);
		$obj->emailFriendDisplay(); // calls CLOSE() internally
	}
// Email single resource to friend
	else if($vars["action"] == 'emailFriend')
	{
		include_once("core/email/EMAIL.php");
		$obj = new EMAIL(FALSE, $vars);
		$obj->emailFriend(); // calls CLOSE() internally
	}
// Administer creators
	else if($vars["action"] == 'adminCreator')
	{
		include_once("core/admin/ADMINCREATOR.php");
		$obj = new ADMINCREATOR($db, $vars);
		$pString = $obj->gateKeep('display');
	}
	else if($vars["action"] == 'mergeCreators')
	{
		include_once("core/admin/ADMINCREATOR.php");
		$obj = new ADMINCREATOR($db, $vars);
		$pString = $obj->gateKeep('mergeProcess');
	}
// Handle requests for user registration
	else if($vars["action"] == 'registerRequestManage')
	{
		include_once("core/admin/ADMINUSER.php");
		$obj = new ADMINUSER($db, $vars);
		$pString =$obj->gateKeep('registerRequestManage');
	}
// Display CMS (Content Management System) pop-up
	else if($vars["action"] == 'cmsDisplay')
	{
		include_once("core/cms/CMS.php");
		$obj = new CMS($db, $vars);
		$obj->display(); // Calls CLOSE internally
	}
	else
	{
// nothing found in the core, so check plug-in modules
		$moduleFound = FALSE;
		if($moduleList)
		{
// To guarantee that the action label is not the same as a core one, the module folder name is prepended to the 
// given action (e.g. folderName_actionName). We must remove the prepend.
			$split = split("_", $vars["action"], 2);
			if(sizeof($split) == 2)
			{
				$moduleName = $split[0];
				$action = $split[1];
				include_once("modules/" . $moduleName . '/index.php');
// class name must be in the form $dirName . MODULE
				$module = $moduleName . "_MODULE";
				$class = new $module($db, $vars, FALSE);
				if(method_exists($class, $action))
				{
					$pString = $class->{$action}();
					$moduleFound = TRUE;
				}
			}
		}
		if(!$moduleFound)
		{
// We've finally come to a dead end.....
			include_once("core/messages/ERRORS.php");
			$errors = new ERRORS();
			include_once("core/template/TEMPLATE.php");
			$template = new TEMPLATE('content');
			$template->setVar('heading', "WIKINDX");
			$template->setVar('body', $errors->text("inputError", "invalid"));
			$pString = $template->process();
		}
	}
// Debugging - print all SESSION variables.
// COMMENT OUT IN PRODUCTION!!!!!!!!!!!!!!!!!!!!!
//global $_SESSION ;
//print_r($_SESSION); print "<P>";
/*****
*	Close the HTML code by calling the constructor of CLOSE which also 
*	prints the HTTP header, body, menus, footer, flushes the print buffer and closes the database.
*****/
	unset($obj);

/* Memory checking
*/
/*
	$output = array();
	exec('pslist -m ' . getmypid() , $output);
	$memEnd = trim(substr($output[$resultRow], $resultRowItemStartPosition, $resultRowItemLength)) / 1000;
	$memScript = $memEnd - $memStart;
	print "Start Memory: $memStart MB<BR>End Memory: $memEnd MB<BR>Script Memory: $memScript MB<P>";
*/

/*
 Print any inline plug-ins
 */
	foreach($plugintopArray as $pluginString)
		$plugintop .= $pluginString;
	foreach($pluginbottomArray as $pluginString)
		$pluginbottom .= $pluginString;
	include_once("core/html/CLOSE.php");
	new CLOSE($db, $pString, $plugintop, $pluginbottom);
?>
